{% extends 'ClassroomBundle:ClassroomManage:layout.html.twig' %}

{% block title %}{{'课程管理'|trans}} - {{ parent() }}{% endblock %}

{% set script_controller = 'classroombundle/controller/classroom/course' %}
{% set side_nav = 'courses' %}

{% block main %}

<style>

.sort{
    padding-top: 50px;
    padding-right: 20px;
    padding-left: 20px;
}

.price{
  color: #e57259;
  font-size: 16px;
}

</style>

{% set url = path('classroom_courses_select',{id:classroom.id}) %}       
<div class="panel panel-default panel-col">
  <div class="panel-heading">{{'课程管理'|trans}}
    <button class="btn btn-success btn-sm panel-bar" data-toggle="modal" data-target="#modal" data-url="{{path('classroom_courses_pick',{classroomId:classroom.id})}}">{{'添加课程'|trans}}</button></div>
  <div class="panel-body">

        <form id="courses-form" class="form-horizontal" method="post">
          {{ web_macro.flash_messages() }}

          <div class="form-group" id="courses-form-group">
            <div class="col-md-12 controls">
              <ul class="course-list-group sortable-list course-wide-list courses-selected" id="course-list-group" data-role="list" >

                {% for course in courses %}

                <li class="course-item item-{{course.id}} clearfix" data-role="item" >
                <input type="hidden" name="courseIds[]" value="{{course.id}}" />
                <span class="glyphicon glyphicon-resize-vertical sort-handle sort"></span>    <a class="course-picture-link" href="{{ path('course_show', {id:course.id}) }}" target="_blank">
                <img class="course-picture" src="{{ filepath(course.middlePicture, 'course.png') }}" alt="{{ course.title }}">
                    </a>
                        <button class="close delete-btn pull-right mrl mts mll" data-role="item-delete" type="button" title="{{'删除'|trans}}" style="font-size:35px;" data-id="{{course.id}}">× </button>
                    <div class="course-body">
                     <div style="float:right;" class="text-muted mrm mls">
                        {% if setting('coin.coin_enabled') and setting('coin.price_type') == 'Coin' %}
                            <span class="course-price course-price-{{course.id}}" style="display:inline" data-price="{{ course.price * setting('coin.cash_rate')}}">
                              {% if course.price > 0 %}
                                {{ course.price * setting('coin.cash_rate')}}
                                {{setting('coin.coin_name')}}
                              {% else %}
                                {{'免费'|trans}}
                              {% endif %}
                            </span>

                        {% else %}
                          <span class="course-price course-price-{{course.id}}" data-price="{{ course.price }}">
                            {% if course.price > 0 %}
                              {{ course.price }} {{'元'|trans}}
                            {% else %}
                              {{'免费'|trans}}
                            {% endif %}
                          </span>
                        {% endif %}
                      </div>

                      <h4 class="course-title"><a href="{{ path('course_show', {id:course.id}) }}" target="_blank">{{ course.title }}</a>
                      {% if course.serializeMode=='serialize' %}
                        <span class="label label-success ">{{'更新中'|trans}}</span>
                      {% elseif course.serializeMode=='finished' %}
                        <span class="label label-warning ">{{'已完结'|trans}}</span>
                      {% endif %}
                      {% if course.type == 'live' %}
                          {% set lesson = course['lesson']|default(null) %}
                          {% if lesson and "now"|date("U") >= lesson.startTime and "now"|date("U") <= lesson.endTime %}
                            <span class="label label-warning">{{'正在直播中'|trans}}</span>
                          {% else %}
                            <span class="label label-success">{{'直播'|trans}}</span>
                          {% endif %}
                      {% endif %}
                      </h4>

                      {% if course.type == 'live' %}
                        {% set lesson = course.lesson|default(null) %}
                        {% if lesson %}
                          <div class="live-course-lesson mbm">
                            <span class="text-success fsm mrm">{{ lesson.startTime|date('m-d H:i') }} ~ {{ lesson.endTime|date('H:i') }}</span>
                            <span class="text-muted fsm mrm">{{'第%number%课时'|trans({'%number%':lesson.number})}}</span>
                          </div>
                        {% endif %}
                      {% else %}
                        <div class="course-about ellipsis">{{ course.subtitle }}</div>
                      {% endif %}

                      <div class="course-footer clearfix">
                        {% set teacher = users[course.teacherIds|first]|default(null) %}
                        {% if teacher %}
                          <div class="teacher">
                            <a href="{{ path('user_show', {id:teacher.id}) }}" target="_blank"><img src="{{ filepath(teacher.smallAvatar, 'avatar.png') }}" class="teacher-avatar"></a>
                            <a class="teacher-nickname ellipsis" target="_blank"  href="{{ path('user_show', {id:teacher.id}) }}">{{ teacher.nickname }}</a>
                            <span class="teacher-title ellipsis">{{ teacher.title }}</span>
                          </div>
                        {% endif %}

                        <div class="course-metas">  

                          {% if setting('course.show_student_num_enabled', '1') == 1  %}
                          <span class="text-muted text-sm">{{ course.studentNum }}{{setting('default.user_name', '学员'|trans)}}</span>
                          <span class="divider"></span>
                          {% endif %}  

                            <span class="text-muted text-sm">
                                {{'%lessonNum%个课时'|trans({'%lessonNum%':course.lessonNum})}}
                            </span>
                            <span class="divider"></span>
                            <span class="text-muted text-sm">
                                {{'有效期:'|trans}}
                                {% if course.expiryDay %}
                                  {% if course.expiryMode|default(null) == 'date' %}
                                    {{course.expiryDay|date('Y-m-d H:i')}}
                                  {% else %}
                                    {{course.expiryDay}}{{'天'|trans}}
                                  {% endif %}
                                {% else %}
                                    {{'永久'|trans}}
                                {% endif %}
                            </span>
                        </div>

                      </div>

                    </div>
                </li>

                {% endfor %}

              </ul>
            </div>  
          </div>

          {% if courses %}
          <div class="alert alert-warning pull-right">{{'若%name%课程被移除，则该课程内所有学习数据将被清空。'|trans({'%name%':setting('classroom.name')|default('班级'|trans)})}}</div>
          <div class="form-group">
            <div class="col-md-offset-9 col-md-3 controls">
              <div class="mbl pull-right">{{'共计:'|trans}} &nbsp; &nbsp;
                  {% if setting('coin.coin_enabled') and setting('coin.price_type') == 'Coin' %}
                    <span class="price" style="display:inline">

                        <span  id="price">{{ coinPrice }}</span>{{setting('coin.coin_name')}}

                    </span>

                  {% else %}
                    <span class="price">

                        <span id="price">{{ price }}</span>{{'元'|trans}}
                      
                    </span>
                  {% endif %}
  
              </div>

              <button type="submit" class="btn btn-fat btn-primary pull-right">{{'保存修改'|trans}}</button>

            </div>  
          </div>
          {% else %}
          <div class="empty">{{'赶紧添加课程吧！'|trans}}</div>
          {% endif %}

          <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">

        </form>

  </div>
</div>

{% endblock %}